﻿using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NM.Module.Manager.API.Commands.Delete;
using NM.Module.Manager.API.Commands.Install;
using NM.Module.Manager.API.Commands.UnInstall;
using NM.Module.Manager.API.Commands.Upload;
using NM.Module.Manager.API.DTOs;
using NM.Module.Manager.API.Queries.PaginationQuery;
using System.ComponentModel;

namespace NM.Module.Manager.API.Controllers;

/// <summary>
/// 模块管理
/// </summary>
[AllowAnonymous]
[Description("模块管理")]
public class ModuleManagerController : BaseModuleController
{
    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [HttpPost("Pagination")]
    [Description("分页查询")]
    public async Task<Result<PaginatedData<ModulerOutput>>> PaginationQuery(ModulersWithPaginationQuery query)
    {
        return await Result<PaginatedData<ModulerOutput>>.SucceedAsync(await Mediator.Send(query));
    }

    /// <summary>
    /// 安装模块
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Install")]
    [Description("安装模块")]
    public async Task<Result<bool>> Install(InstallModulerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 卸载模块
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("UnInstall")]
    [Description("卸载模块")]
    public async Task<Result<bool>> UnInstall(UnInstallModulerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 上传模块
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Upload")]
    [Description("上传模块")]
    public async Task<Result<bool>> Upload(UploadModulerCommand command)
    {
        return await Mediator.Send(command);
    }

    /// <summary>
    /// 删除模块
    /// </summary>
    /// <param name="command"></param>
    /// <returns></returns>
    [HttpPost("Delete")]
    [Description("删除模块")]
    public async Task<Result<bool>> Delete(DeleteModulerCommand command)
    {
        return await Mediator.Send(command);
    }
}
